package cm.example.shoppingplatformspringboot.controller;

import cm.example.shoppingplatformspringboot.entity.Invoice;
import cm.example.shoppingplatformspringboot.service.InvoiceService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static cm.example.shoppingplatformspringboot.utils.ResponseUtil.generateResponse;

@RestController
@RequestMapping("/invoice")
public class InvoiceController {
    @Resource
    private InvoiceService invoiceService;

    // 更新发票
    @PutMapping("/updateInvoice")
    public ResponseEntity<Map<String, Object>> updateInvoice(@RequestBody Invoice invoice) {
        Invoice updatedInvoice = invoiceService.updateInvoice(invoice);
        if (updatedInvoice != null) {
            return generateResponse("success", "发票更新成功", updatedInvoice);
        } else {
            return generateResponse("error", "发票更新失败", null);
        }
    }
}